package megrez.keycloak.providers.mqtt;

import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.IMqttMessageListener;
import org.eclipse.paho.client.mqttv3.IMqttToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttTopic;

import lombok.extern.slf4j.Slf4j;
import megrez.keycloak.common.KeycloakEmbeddedException;

/**
 * mqtt 日志实现
 * 
 * @author Lucky Yang
 * @since 2.6.9
 */
@Slf4j
public class LoggerMqttService implements MqttService {
    private static final KeycloakEmbeddedException METHOD_NOT_SUPPORT = new KeycloakEmbeddedException("Method not supported");

    @Override
    public void close() {
        // 不需要实现
    }

    @Override
    public void connect() throws MqttException {
        log.info("connect()");
    }

    @Override
    public void connect(MqttConnectOptions options) throws MqttException {
        log.info("connect(MqttConnectOptions options) ");
    }

    @Override
    public IMqttToken connectWithResult(MqttConnectOptions options) throws MqttException {
        throw METHOD_NOT_SUPPORT;
    }

    @Override
    public void disconnect() throws MqttException {
        log.info("disconnect()");
    }

    @Override
    public void disconnect(long quiesceTimeout) throws MqttException {
        log.info("disconnect(long quiesceTimeout)");
    }

    @Override
    public void disconnectForcibly() throws MqttException {
        log.info("disconnectForcibly()");
    }

    @Override
    public void disconnectForcibly(long disconnectTimeout) throws MqttException {
        log.info("disconnectForcibly(long disconnectTimeout)");
    }

    @Override
    public void disconnectForcibly(long quiesceTimeout, long disconnectTimeout) throws MqttException {
        log.info("disconnectForcibly(long quiesceTimeout, long disconnectTimeout)");
    }

    @Override
    public void subscribe(String topicFilter) throws MqttException {
        log.info("subscribe(String topicFilter)");
    }

    @Override
    public void subscribe(String[] topicFilters) throws MqttException {
        log.info("subscribe(String[] topicFilters) ");
    }

    @Override
    public void subscribe(String topicFilter, int qos) throws MqttException {
        log.info("subscribe(String topicFilter, int qos)");
    }

    @Override
    public void subscribe(String[] topicFilters, int[] qos) throws MqttException {
        log.info("subscribe(String[] topicFilters, int[] qos)");
    }

    @Override
    public void subscribe(String topicFilter, IMqttMessageListener messageListener)
            throws MqttException {
        log.info("subscribe(String topicFilter, IMqttMessageListener messageListener)");
    }

    @Override
    public void subscribe(String[] topicFilters, IMqttMessageListener[] messageListeners) throws MqttException {
        log.info("subscribe(String[] topicFilters, IMqttMessageListener[] messageListeners)");
    }

    @Override
    public void subscribe(String topicFilter, int qos, IMqttMessageListener messageListener) throws MqttException {
        log.info("subscribe(String topicFilter, int qos, IMqttMessageListener messageListener)");
    }

    @Override
    public void subscribe(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners)
            throws MqttException {
        log.info("subscribe(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners)");
    }

    @Override
    public IMqttToken subscribeWithResponse(String topicFilter) throws MqttException {
        throw METHOD_NOT_SUPPORT;
    }

    @Override
    public IMqttToken subscribeWithResponse(String topicFilter, IMqttMessageListener messageListener)
            throws MqttException {
        throw METHOD_NOT_SUPPORT;
    }

    @Override
    public IMqttToken subscribeWithResponse(String topicFilter, int qos) throws MqttException {
        throw METHOD_NOT_SUPPORT;
    }

    @Override
    public IMqttToken subscribeWithResponse(String topicFilter, int qos, IMqttMessageListener messageListener)
            throws MqttException {
        throw METHOD_NOT_SUPPORT;
    }

    @Override
    public IMqttToken subscribeWithResponse(String[] topicFilters) throws MqttException {
        throw METHOD_NOT_SUPPORT;
    }

    @Override
    public IMqttToken subscribeWithResponse(String[] topicFilters, IMqttMessageListener[] messageListeners)
            throws MqttException {
        throw METHOD_NOT_SUPPORT;
    }

    @Override
    public IMqttToken subscribeWithResponse(String[] topicFilters, int[] qos) throws MqttException {
        throw METHOD_NOT_SUPPORT;
    }

    @Override
    public IMqttToken subscribeWithResponse(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners)
            throws MqttException {
        throw METHOD_NOT_SUPPORT;
    }

    @Override
    public void unsubscribe(String topicFilter) throws MqttException {
        log.info("unsubscribe(String topicFilter)");
    }

    @Override
    public void unsubscribe(String[] topicFilters) throws MqttException {
        log.info("unsubscribe(String[] topicFilters)");
    }

    @Override
    public void publish(String topic, byte[] payload, int qos, boolean retained)
            throws MqttException {
        MqttMessage message = new MqttMessage();
        message.setQos(qos);
        message.setRetained(retained);
        message.setPayload(payload);
        this.publish(topic, message);
    }

    @Override
    public void publish(String topic, MqttMessage message) throws MqttException {
        log.info("Pulish message to Mqtt broker: topic={}, qos={}, retained={}, payload={}", topic, message.getQos(),
                message.isRetained(), message.toString());
    }

    @Override
    public void setCallback(MqttCallback callback) {
        log.info("setCallback(MqttCallback callback)");

    }

    @Override
    public MqttTopic getTopic(String topic) {
        throw METHOD_NOT_SUPPORT;
    }

    @Override
    public boolean isConnected() {
        log.info("isConnected()");
        return false;
    }

    @Override
    public String getClientId() {
        throw METHOD_NOT_SUPPORT;
    }

    @Override
    public String getServerURI() {
        throw METHOD_NOT_SUPPORT;
    }

    @Override
    public IMqttDeliveryToken[] getPendingDeliveryTokens() {
        throw METHOD_NOT_SUPPORT;
    }

    @Override
    public void setManualAcks(boolean manualAcks) {
        log.info("setManualAcks(boolean manualAcks)");
    }

    @Override
    public void reconnect() throws MqttException {
        log.info("reconnect()");
    }

    @Override
    public void messageArrivedComplete(int messageId, int qos) throws MqttException {
        log.info("messageArrivedComplete(int messageId, int qos)");
    }

}
